package com.hnust.dao;

import com.hnust.domain.GradRequirement;
import com.hnust.domain.Major;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 *创建人：游磊
 *创建时间：2020/10/6
 *描述：
 */
@Mapper
@Repository
public interface MajorDao {

    //根据学院ID获取专业总数
    @Select("select count(*) from major where col_id=#{collegeId}")
    @ResultType(Integer.class)
    Integer findMajorCountByCollegeId(String collegeId);

    //根据专业ID获取专业名
    @Select("select name from major where maj_id=#{majorId}")
    @ResultType(String.class)
    String findNameByMajorId(String majorId);

    // 根据学院id获取所有专业  limit #{rows} offset #{current}
    @Select("select * from major where col_id=#{collegeId}")
    @ResultType(Major.class)
    List<Major> getMajorListByCollegeId(String collegeId,int rows,int current);

    // 根据学院id以及专业名字获取所有专业  limit #{rows} offset #{current}
    @Select("select * from major where col_id=#{collegeId} and name like CONCAT('%',#{name},'%')")
    @ResultType(Major.class)
    List<Major> getMajorListByCollegeIdAndMajorName(String collegeId,int rows,int current,String name);

    // 删除专业(这里我们使用$，不自己主动加“转义)
    @Delete("delete from major where maj_id IN (${majorId})")
    int deleteMajorByMajorId(String majorId);

    // 添加专业
    @Insert("insert into major (maj_id,name,col_id) values (#{majorId},#{name},#{collegeId})")
    int addMajor(String majorId,String name,String collegeId);


    // 修改专业名字
    @Update("update major set name = #{name} where maj_id = #{majorId}")
    int updateMajorName(String majorId,String name);

    //根据专业名获取专业ID
    @Select("select maj_id from major where name=#{name}")
    @ResultType(String.class)
    public String findMajorIdByName(String name);

    //根据专业名获取专业Id级col_id
    @Select("select maj_id,col_id from major where name=#{name}")
    Map getMajorId(@Param("name") String name);


    /*
     * @Author Tonited
     * @Description //TODO 根据专业编号获取到专业ID
     * @Date 17:03 2020/10/29
     * @Param [num专业编号]
     * @return java.lang.String
     **/
    @Select("select maj_id from major where maj_num=#{num} and col_id=#{collageId}")
    @ResultType(String.class)
    String getMajIdByMajNum(String num,String collageId);


    @Select("select * from major where maj_id=#{majorId}")
    @ResultType(Major.class)
    Major getMajor(String majorId);


}
